package router

import (
	"service/controller"
	"service/middleware"

	"github.com/gin-contrib/gzip"
	"github.com/gin-gonic/gin"
	"github.com/spf13/viper"
)

var Router *gin.Engine

func InitRouter() {
	Router = gin.Default()
	Router.Use(gin.Recovery())
	go Manager.Start()
	Router.Use(middleware.CORSMiddleware())
	// 定义导出Excel的路由
	Router.StaticFS("/uploads", gin.Dir("./uploads", true))
	Router.Use(gzip.Gzip(gzip.DefaultCompression))
	Router.GET("/ping", controller.PingTestController())
	UseSocketRouter(Router)
	UserRouter(Router.Group("/user"))
	FileRouter(Router.Group("/file"))
	UseAttributeRouter(Router.Group("/attribute"))
	MenuRouter(Router.Group("/menu"))
	DepartmentRouter(Router.Group("/department"))
	port := viper.GetString("service.port")
	//err := http.ListenAndServeTLS(":"+port, "lianghj.top.pem", "lianghj.top.key", Router)
	//if err != nil {
	//	panic(err)
	//}
	Router.Run(":" + port) // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
